package warmachinesystem.provider;

import java.net.URL;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;

import warmachinesystem.ArmyList;

public class ArmyListTableLabelProvider implements ITableLabelProvider {

	@Override
	public void removeListener(ILabelProviderListener listener) {
	}
	
	@Override
	public boolean isLabelProperty(Object element, String property) {
		if(property.equals("name"))
			return true;
		return false;
	}
	
	@Override
	public void dispose() {
	}
	
	@Override
	public void addListener(ILabelProviderListener listener) {
	}
	
	@Override
	public String getColumnText(Object element, int columnIndex) {
		if (columnIndex == 0)
			return ((ArmyList)element).getName();
		return null;
	}
	
	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		// TODO rifattorizzare e centralizzare il recupero delle immagini
		String imgKey = "full/obj32/" + ((ArmyList)element).getCode() + "_32.png";
		URL imgUrl = (URL) WarmachineSystemEditPlugin.INSTANCE.getImage(imgKey);
		ImageDescriptor id = ImageDescriptor.createFromURL(imgUrl);
		
		return id.createImage();
	}

}
